var ys = {
    //对象的键可以加引号，和不加引号效果是一样的,除非你的键中用到空格。
    'hp': 500,
    mp: 0,
    hj: 50,
    gjl: 80,
    name: "快乐风男",
    skills: ["斩钢", "风墙", "e", "r"],
    kh: ["面对疾风吧！", "哈萨key", "长路漫漫，唯剑作伴"],
    zb: [],
    dj: 1,
    wlfy: function() {
        return 1 - this.hj / 500
    },

    say: function() {
        //i是一个随机数
        var i = Math.round(Math.random() * (this.kh.length - 1))
        console.log(this.kh[i])
    },
    //攻击方法
    attack: function(hero) {
        //在攻击之前首先判断对方英雄的血量，如果<=0就不进行攻击。
        if (hero.hp <= 0) {
            console.log(`${hero.name}已经挂了，不要在鞭尸了！`);
            //return以后的代码都不执行
            return
        }
        this.say();
        var loss = this.gjl * hero.wlfy()
        hero.hp -= loss;
        //攻击之后如果对方英雄的血量小于0则置为0
        if (hero.hp <= 0) {
            hero.hp = 0
        }
        console.log(`${this.name}攻击了${hero.name}`);
        console.log(`${hero.name}减少血量${loss}，剩余血量${hero.hp}`);
        if (hero.hp <= 0) {
            console.log(`${hero.name}挂了`)
        }
    },
}

var zx = {
    hp: 600,
    mp: 400,
    hj: 70,
    gjl: 85,
    name: "菊花信",
    skills: ["q", "w", "e", "r"],
    kh: ["长枪依在，菊花拿来", "一点寒芒先到，随后菊花就爆", "万军之中取你首级"],
    zb: [],
    dj: 1,
    wlfy: function() {
        return 1 - this.hj / 500
    },
    attack: function(hero) {
        // console.log(this);
        if (hero.hp <= 0) {
            console.log(`${hero.name}已经挂了，不要在鞭尸了！`);
            return
        }
        this.say();
        var loss = this.gjl * hero.wlfy()
        hero.hp -= loss;
        if (hero.hp <= 0) {
            hero.hp = 0
        }
        console.log(`${this.name}攻击了${hero.name}`);
        console.log(`${hero.name}减少血量${loss}，剩余血量${hero.hp}`);
        if (hero.hp <= 0) {
            console.log(`${hero.name}挂了`)
        }
    },
    say: function() {
        var i = Math.round(Math.random() * 2)
        console.log(this.kh[i])
    }
}